package edu.gmu.jchanlau.week02.assignment;

/** Some comments
 * 
 * @author LocalAdmin
 *
 */
public class Week2 {


    /**
     * Take the average of all the elements in the array.
     * 
     * @param nums
     * @return
     */
    public static double averageElements(double[] nums) {
        double meanArray=0.0;
        for (int i=0; i<nums.length; i++){
                        meanArray=meanArray+nums[i];
                }
                meanArray=1.0*meanArray/nums.length;    
            return meanArray;
    }

    /**
     * Square each of the elements and return the values in an array.
     * 
     * @param nums
     * @return
     */
    public static double[] squareElements(double[] nums) {
        double[] doubleSquaredArray;
        doubleSquaredArray = new double [nums.length];
        for (int i=0; i<nums.length; i++){
                doubleSquaredArray[i]=nums[i]*nums[i];
        }
        return doubleSquaredArray;              
    }   

    public static void main(String[] args) {
    	double[] nums1, nums2; 
    	nums1 = new double[] {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
    	nums2 = new double[nums1.length];
    	System.out.println("The average of the elements is "+squareElements(nums1));
    	
    	nums2=squareElements(nums1);
    	for (int i=1; i<nums1.length+1; i++){
    		System.out.println("The square of element " +i+ " is " + nums2[i-1] );
    	}
    }
}